




PROCEDURE cimloadprocess:

    define input parameter vc_cimfile  as character no-undo.
    define input parameter vc_cimlog   as character no-undo.
    define input parameter vc_program  as character no-undo.
    define input parameter vc_traceid  as character no-undo.
    define input parameter vc_dataid   as character no-undo.
    define input parameter vc_billnbr   as character no-undo.
    define output parameter vc_errormsg as character no-undo.
    define output parameter vl_errorstatus as logical no-undo.
    define variable vi_seq as integer no-undo.
    define variable vc_line as character no-undo.
  
    vi_seq = 0.

    cimloop:
        do transaction on error undo cimloop, leave cimloop:         
            batchrun = yes.
            output to value(vc_cimlog).
            if execname = "xxissunpapi.p" then 
            input from value(vc_cimfile) convert source "CP936" target "UTF-8"  .
            else 
            input from value(vc_cimfile) .

            {us/bbi/gprun.i vc_program}

            input close.
            output close.
            batchrun = no.
                
            vl_errorstatus = no.
            vc_errormsg = "".
                FILE-INFO:filename = (vc_cimlog).
                if FILE-INFO:file-size > 0 then
                do:
                input from value(vc_cimlog).              
                repeat:
                import unformatted vc_line.
                  if index(vc_line, getTermLabel("Error",5)) <> 0 or 
                     index(vc_line, "**") <> 0  then
                     do:
                        assign vl_errorstatus    = yes
                             /*  vc_errormsg = vc_line + "|" + vc_errormsg */.

                        vi_seq = vi_seq + 1.        
                        create api_status.
                        assign api_status.data_seq     = vi_seq
                               api_status.return_status  = "FAILED"
                               api_status.message_type = "CIM"
                               api_status.message_string  = vc_line
                               api_status.domain  = global_domain
                               api_status.dataid = vc_dataid
                               api_status.traceid = vc_traceid
                               api_status.billnbr = vc_billnbr
                               
                               .

                        leave.
                   end. /* end if index */                      
                end. /* repeat */               
                input close. /* input from value(vc_cimlog). */        
                end. /* if exist log file */                
                else do:
                    vl_errorstatus = yes.
                    vc_errormsg = "LOG FILE NOT EXIST".
                    vi_seq = vi_seq + 1.        
                        create api_status.
                        assign api_status.data_seq     = vi_seq
                               api_status.return_status  = "FAILED"
                               api_status.message_type = "CIM"
                               api_status.message_string  = vc_errormsg
                               api_status.dataid = vc_dataid
                               api_status.domain = global_domain
                               api_status.traceid = vc_traceid
                               api_status.billnbr = vc_billnbr
                               .
                end.
                
                if vl_errorstatus then
                do:
                  undo cimloop , leave cimloop.                     
                 
                end. 
                find first api_status where (api_status.return_status = "FAILED"  
                                          and  api_status.dataid = vc_dataid 
                                          and api_status.billnbr = vc_billnbr )
                                        
                                         or (api_status.return_status matches "SUCCESS*" 
                                          and api_status.dataid = vc_dataid
                                          and api_status.billnbr = vc_billnbr)
                                         no-error.
                if not available api_status then
                do:
                vi_seq = vi_seq + 1.        
                create api_status.
                assign api_status.data_seq     = vi_seq
                       api_status.return_status  = "SUCCESS"
                       api_status.message_type = "CIM"
                       api_status.message_string  = ""
                       api_status.dataid = vc_dataid
                       api_status.domain = global_domain
                       api_status.traceid = vc_traceid
                       api_status.billnbr = vc_billnbr
                       
                       .
                end. /*   if not available api_status then */
         end. /* do transaction on error undo cimloop, leave cimloop:        */

END.


PROCEDURE cimfilehandle:

    define input parameter vc_filename as character no-undo.
    define input parameter vc_topath     as character no-undo.
    define input parameter vl_delete as logical no-undo.



    if vl_delete then do:                 
        /* Delete file from work */
        FILE-INFO:filename = (vc_filename).
        if FILE-INFO:file-size >= 0 then
        do:
            unix silent value("chmod 766 " + vc_filename).
            unix silent value("rm -f " + vc_filename).
        end.
    end.
    else do:
        /* Move file from work to to_path */      
        FILE-INFO:filename = (vc_filename).
        if FILE-INFO:file-size >= 0 then
        do:
            unix silent value("chmod 766 " + vc_filename).
            unix silent value("mv " + vc_filename + ' ' +  vc_topath).
        end.
    end.
end. /* cimfilehandle */